package com.goal98.team.domain

import com.goal98.grails.plugin.account.domain.Account

class Team {

    static searchable = {
        analyzer 'chinese'
        members reference: true
        activities reference: true
    }

    String name
    Date dateCreated
    Date lastUpdated
    Account account


    static hasMany = [members: Person, activities:Activity]
    static transients = ['teamAdmins']

    List getTeamAdmins(){
        def result = []
        members?.each{Person member->
            if(member.isTeamAdmin()){
                result << member
            }
        }
        return result
    }

    static constraints = {
        name(unique: true)
        account(nullable:true)
    }

    String toString(){
        return name
    }

    static mapping = {
        cache true
        members cache:true
        activities cache:true
    }
}
